package com.sugar.follow.up.module.business.util.wechat;

import cn.hutool.core.util.XmlUtil;

import java.util.HashMap;
import java.util.Map;

public class MsgUtil {

    public static final String MSGTYPE_EVENT = "event";//消息类型--事件
    public static final String MESSAGE_SUBSCIBE = "subscribe";//消息事件类型--订阅事件
    public static final String MESSAGE_UNSUBSCIBE = "unsubscribe";//消息事件类型--取消订阅事件
    public static final String MESSAGE_TEXT = "text";//消息类型--文本消息

    /**
     * 组装文本消息
     */
    public static String textMsg(String toUserName,String fromUserName,String content){
        Map<String, Object> params = new HashMap<>();
        params.put("fromUserName", toUserName);
        params.put("toUserName", fromUserName);
        params.put("msgType", MESSAGE_TEXT);
        params.put("createTime", System.currentTimeMillis());
        params.put("content", content);
        return XmlUtil.mapToXmlStr(params);
    }

    /**
     * 响应订阅事件--回复文本消息
     */
    public static String subscribeForText(String toUserName,String fromUserName,String content){
        return textMsg(toUserName, fromUserName, content);
    }

    /**
     * 响应取消订阅事件
     */
    public static String unsubscribeForText(String toUserName,String fromUserName,String content){
        System.out.println("用户："+ fromUserName +"取消关注~");
        return "";
    }
}
